package com.xyd.Servlet;

import com.xyd.Biz.FatherOrderBiz;
import com.xyd.Biz.Impl.FatherOrderBizImpl;
import com.xyd.Biz.Impl.OrderFormBizImpl;
import com.xyd.Biz.OrderFormBiz;
import com.xyd.Entity.OrderForm;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sound.midi.Soundbank;
import java.io.IOException;
import java.util.List;

/**
 * @ClassName: ConfirmReceiptServlet
 * @Description:点击确认收货按钮触发，更新订单的状态
 * @Author 余全盛
 * @Date: 2021/10/21 10:35
 */
@WebServlet("/ConfirmReceiptServlet")
public class ConfirmReceiptServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        FatherOrderBiz fatherOrderBiz = new FatherOrderBizImpl();
        long fatherorderid = Long.parseLong(req.getParameter("fatherorderid"));
        int sonorderid = Integer.parseInt(req.getParameter("sonorderid"));

        OrderFormBiz orderFormBiz = new OrderFormBizImpl();
        orderFormBiz.updateSonOrderState(3, sonorderid);
        List<OrderForm> orderForms = orderFormBiz.selectSonOrder(fatherorderid);
        boolean flag = true;
        for (OrderForm orderForm : orderForms) {
            if (orderForm.getSonorderstate() != 3) {
                flag = false;
            }
        }
        if (flag) {
            fatherOrderBiz.updateFatherOrderState(3, fatherorderid);
        }
        resp.sendRedirect("/shopping/html/ShowOrderServlet");

    }
}
